﻿using Microsoft.AspNetCore.Authorization;
using Publicuse.Interface;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Publicuse.WebCore.AuthorizationExtend
{
    /// <summary>
    /// 核心判断
    /// 在这里就可以做自己要做的业务判断
    /// </summary>
    public class MenuAuthorizeHandler : AuthorizationHandler<MenuAuthorizeRequirement>
    {

        private readonly IMySqlSugarService  mySqlSugar=null;

        /// <summary>
        /// 构造函数注入
        /// </summary>
        /// <param name="mySqlSugar"></param>

        public MenuAuthorizeHandler(IMySqlSugarService mySqlSugar)
        {
            this.mySqlSugar = mySqlSugar;
        }

        /// <summary>
        /// 验证核心业务逻辑
        /// </summary>
        /// <param name="context"></param>
        /// <param name="requirement"></param>
        /// <returns></returns>
        protected override async Task HandleRequirementAsync(AuthorizationHandlerContext context, MenuAuthorizeRequirement requirement)
        {
            //if (context.User.Claims == null || context.User.Claims.Count() <= 0)
            //{
            //    context?.Fail();
            //}
            //else if (context.User.IsInRole("admin"))
            //{
            context?.Succeed(requirement);//只要执行这句话就表示验证通过了
            //} 
            await Task.CompletedTask;
        }
    }
}
